package smartcampus.scjava.controller.second;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import smartcampus.scjava.POJO.DO.Tuition;
import smartcampus.scjava.POJO.DO.TuitionFee;
import smartcampus.scjava.POJO.DTO.TuitionFeeDTO;
import smartcampus.scjava.custom.ResultVO;
import smartcampus.scjava.service.TuitionFeeService;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/tuitionfee")
@ApiOperation("学费管理")
public class TuitionFeeController {

    @Autowired
    TuitionFeeService tuitionFeeService;


    @GetMapping("/selectOneByStuiid")
    @ApiOperation("根据学号查询学费")
    public ResultVO<?> selectOneByStuiid(String stuid) {
        QueryWrapper<TuitionFee> qw = new QueryWrapper<TuitionFee>();
        qw.eq("stuId", stuid);
        TuitionFee student1 = tuitionFeeService.getOne(qw);
        if (null != student1) {
            return ResultVO.success(student1);
        } else {
            return ResultVO.fail("未查询到该学号学生信息");
        }
    }

    @ApiOperation("新增一条学费缴纳记录")
    public void addTuition(String stuid){
        //直接初始化一条学费记录
        TuitionFee tuitionFee = new TuitionFee();
        tuitionFee.setStuid(stuid);
        tuitionFee.setPaid(0);
        tuitionFee.setFeepayable(null);
        tuitionFee.setIssubmit(0);
        tuitionFee.setIsDelete(0);
        Date now1 = new Date();
        tuitionFee.setCreateTime(now1);
        tuitionFeeService.saveOrUpdate(tuitionFee);
        System.out.println("新增一条学费记录");
    }


    @ApiOperation("需缴纳金额总计")
    public int updateByStuId() {
        int s = tuitionFeeService.updateSumMoney();
        return s;
    }

    @GetMapping("/selectTuitionList")
    @ApiOperation("根据学号查询一个学生的学费详情")
    public  ResultVO<?> selectTuitionList(String stuid){
        List list = new ArrayList();
       List<TuitionFeeDTO> tuitionList= tuitionFeeService.selectTuitionList(stuid);
         return ResultVO.success(tuitionList);
    }


}
